package com.example.demo;

import com.alibaba.fastjson.JSON;


import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;

import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;



import java.lang.reflect.Method;




//声明该类要处理的包路径
@ControllerAdvice
public class ResponseAdvice implements ResponseBodyAdvice {


    // 对response处理的具体方法
    @Override
    public Object beforeBodyWrite(Object body, MethodParameter methodParameter,
                                  MediaType mediaType, Class c, ServerHttpRequest serverHttpRequest,
                                  ServerHttpResponse serverHttpResponse) {/*
        System.out.println("---------开始-------");
        System.out.println("request-header:" + serverHttpRequest.getHeaders());
        Method method=methodParameter.getMethod();
        String url=serverHttpRequest.getURI().toASCIIString();
        System.out.println("method="+method.getDeclaringClass().getSimpleName());
        System.out.println("name="+method.getName());
        System.out.println("url="+url);
        System.out.println("data="+JSON.toJSONString(body));
        System.out.println("---------结束-------");*/

        return body;
    }

    @Override
    public boolean supports(MethodParameter returnType, Class converterType) {
        return true;
    }


}
